// $ANTLR 2.7.5 (20050128): "parser-files/WPFileFormata27.g" -> "WPDataParser.java"$

/*******************************************************************************
 * Copyright (c) 2008 Nels E. Beckman.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Nels E. Beckman - initial API and implementation
 *******************************************************************************/
 
package edu.cmu.cs.nbeckman.wptranslator.parser;
 
import edu.cmu.cs.nbeckman.wptranslator.*;
import java.util.*;

import antlr.TokenBuffer;
import antlr.TokenStreamException;
import antlr.TokenStreamIOException;
import antlr.ANTLRException;
import antlr.LLkParser;
import antlr.Token;
import antlr.TokenStream;
import antlr.RecognitionException;
import antlr.NoViableAltException;
import antlr.MismatchedTokenException;
import antlr.SemanticException;
import antlr.ParserSharedInputState;
import antlr.collections.impl.BitSet;

public class WPDataParser extends antlr.LLkParser       implements WPDataParserTokenTypes
 {

protected WPDataParser(TokenBuffer tokenBuf, int k) {
  super(tokenBuf,k);
  tokenNames = _tokenNames;
}

public WPDataParser(TokenBuffer tokenBuf) {
  this(tokenBuf,1);
}

protected WPDataParser(TokenStream lexer, int k) {
  super(lexer,k);
  tokenNames = _tokenNames;
}

public WPDataParser(TokenStream lexer) {
  this(lexer,1);
}

public WPDataParser(ParserSharedInputState state) {
  super(state,1);
  tokenNames = _tokenNames;
}

	public final Document  first() throws RecognitionException, TokenStreamException {
		Document d;
		
		Element el;
		d = null;
		
		
		try {      // for error handling
			el=elementList();
			match(Token.EOF_TYPE);
			d = new Document(el);
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_0);
		}
		return d;
	}
	
	public final Element  elementList() throws RecognitionException, TokenStreamException {
		Element e;
		
		List<Element> l = new LinkedList<Element>();
		e = null;
		Element e1;
		
		
		try {      // for error handling
			{
			int _cnt4=0;
			_loop4:
			do {
				if ((_tokenSet_1.member(LA(1)))) {
					e1=element();
					l.add(e1);
				}
				else {
					if ( _cnt4>=1 ) { break _loop4; } else {throw new NoViableAltException(LT(1), getFilename());}
				}
				
				_cnt4++;
			} while (true);
			}
			e = new ElementList(l);
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_2);
		}
		return e;
	}
	
	public final Element  element() throws RecognitionException, TokenStreamException {
		Element e;
		
		Token  ch = null;
		
		e = null;
		Element e1;
		String t1;
		
		
		try {      // for error handling
			switch ( LA(1)) {
			case HYPHEN:
			case PERIOD:
			case SPACE:
			case LLETTER:
			case ULETTER:
			case OTHER:
			{
				t1=text();
				e = new Text(t1);
				break;
			}
			case BBOLD:
			{
				match(BBOLD);
				e1=elementList();
				match(EBOLD);
				e = new BoldedElement(e1);
				break;
			}
			case BCENTER:
			case WEIRDBCENTER:
			{
				{
				switch ( LA(1)) {
				case BCENTER:
				{
					match(BCENTER);
					break;
				}
				case WEIRDBCENTER:
				{
					match(WEIRDBCENTER);
					break;
				}
				default:
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				}
				}
				e1=elementList();
				match(ECENTER);
				e = new CenteredElement(e1);
				break;
			}
			case HRETURN:
			{
				match(HRETURN);
				e = LineBreak.singleton();
				break;
			}
			case BUNDERLINE:
			{
				match(BUNDERLINE);
				e1=elementList();
				match(EUNDERLINE);
				e = new UnderlinedElement(e1);
				break;
			}
			case BINDENT:
			{
				match(BINDENT);
				match(HRETURN);
				ch = LT(1);
				matchNot(EOF);
				match(BINDENT);
				e1=elementList();
				match(EINDENT);
				matchNot(EOF);
				match(OTHERENDINDENT);
				match(EINDENT);
				e=new Indent(e1,ch.getText().toCharArray()[0]);
				break;
			}
			case WEIRDBDINDENT:
			{
				match(WEIRDBDINDENT);
				e1=elementList();
				match(WEIRDEDINDENT);
				e=new DoubleIndent(e1);
				break;
			}
			case TAB:
			{
				match(TAB);
				e=Tab.singleton();
				break;
			}
			default:
			{
				throw new NoViableAltException(LT(1), getFilename());
			}
			}
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_3);
		}
		return e;
	}
	
	public final String  text() throws RecognitionException, TokenStreamException {
		String r;
		
		
		r = "";
		StringBuffer buf = new StringBuffer();
		String ch = "";
		String pu = "";
		
		
		try {      // for error handling
			{
			int _cnt9=0;
			_loop9:
			do {
				if (((LA(1) >= LLETTER && LA(1) <= OTHER))) {
					ch=character();
					buf.append(ch);
				}
				else if (((LA(1) >= HYPHEN && LA(1) <= SPACE))) {
					pu=punctuation();
					buf.append(pu);
				}
				else {
					if ( _cnt9>=1 ) { break _loop9; } else {throw new NoViableAltException(LT(1), getFilename());}
				}
				
				_cnt9++;
			} while (true);
			}
			r = buf.toString();
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_3);
		}
		return r;
	}
	
	public final String  character() throws RecognitionException, TokenStreamException {
		String r;
		
		Token  l = null;
		Token  u = null;
		Token  o = null;
		
		r = "";
		
		
		try {      // for error handling
			switch ( LA(1)) {
			case LLETTER:
			{
				l = LT(1);
				match(LLETTER);
				r = l.getText();
				break;
			}
			case ULETTER:
			{
				u = LT(1);
				match(ULETTER);
				r = u.getText();
				break;
			}
			case OTHER:
			{
				o = LT(1);
				match(OTHER);
				r = o.getText();
				break;
			}
			default:
			{
				throw new NoViableAltException(LT(1), getFilename());
			}
			}
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_3);
		}
		return r;
	}
	
	public final String  punctuation() throws RecognitionException, TokenStreamException {
		String r;
		
		
		r = "";
		
		
		try {      // for error handling
			switch ( LA(1)) {
			case HYPHEN:
			{
				match(HYPHEN);
				r = "-";
				break;
			}
			case PERIOD:
			{
				match(PERIOD);
				r = ".";
				break;
			}
			case SPACE:
			{
				match(SPACE);
				r = " ";
				break;
			}
			default:
			{
				throw new NoViableAltException(LT(1), getFilename());
			}
			}
		}
		catch (RecognitionException ex) {
			reportError(ex);
			recover(ex,_tokenSet_3);
		}
		return r;
	}
	
	
	public static final String[] _tokenNames = {
		"<0>",
		"EOF",
		"<2>",
		"NULL_TREE_LOOKAHEAD",
		"BBOLD",
		"EBOLD",
		"BCENTER",
		"WEIRDBCENTER",
		"ECENTER",
		"HRETURN",
		"BUNDERLINE",
		"EUNDERLINE",
		"BINDENT",
		"EINDENT",
		"OTHERENDINDENT",
		"WEIRDBDINDENT",
		"WEIRDEDINDENT",
		"TAB",
		"HYPHEN",
		"PERIOD",
		"SPACE",
		"LLETTER",
		"ULETTER",
		"OTHER",
		"DIGIT"
	};
	
	private static final long[] mk_tokenSet_0() {
		long[] data = { 2L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
	private static final long[] mk_tokenSet_1() {
		long[] data = { 16684752L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_1 = new BitSet(mk_tokenSet_1());
	private static final long[] mk_tokenSet_2() {
		long[] data = { 76066L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_2 = new BitSet(mk_tokenSet_2());
	private static final long[] mk_tokenSet_3() {
		long[] data = { 16760818L, 0L};
		return data;
	}
	public static final BitSet _tokenSet_3 = new BitSet(mk_tokenSet_3());
	
	}
